<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!--#include file="../inc/conn.asp"-->
<!--#include file="../inc/md5.asp"-->
<!--#include file="../common/admin.asp"-->
<%
key=request.QueryString("key")
SellerID=request.QueryString("SellerID")
Itemnumber=request.QueryString("Itemnumber")
uid=request.QueryString("uid")
mark=request.QueryString("mark")
pay=request.QueryString("pay")
typeid=request.QueryString("typeid")
search=request.QueryString("search")

if typeid="0" then
   sqlsearch=sqlsearch+" and (datediff(minute,'"&now()&"',endtime)>0) and BidsPrice>=price "
elseif typeid="1" then
   sqlsearch=sqlsearch+" and type=1 and (datediff(minute,'"&now()&"',endtime)>0) and BidsPrice>=price "
elseif typeid="2" then
   sqlsearch=sqlsearch+" and type=2 "
elseif typeid="3" then
   sqlsearch=sqlsearch+" and type=3 "
elseif typeid="4" then
   sqlsearch=sqlsearch+" and datediff(minute,'"&now()&"',endtime)>0 and BidsPrice<price "
elseif typeid="5" then
   sqlsearch=sqlsearch+" and datediff(minute,'"&now()&"',endtime)<0 and type<>2 and type<>3 "
end if

if search="搜索" then
	  if key<>"" then
			sqlsearch=sqlsearch+" and (title like '%"&key&"%')"
	  end if
	  if SellerID<>"" then
			sqlsearch=sqlsearch+" and (SellerID like '%"&SellerID&"%')"
	  end if
	  if Itemnumber<>"" then
			sqlsearch=sqlsearch+" and (Itemnumber like '%"&Itemnumber&"%')"
	  end if
	  if uid<>"" then
			sqlsearch=sqlsearch+" and uid='"&uid&"'"
	  end if
end if


'分页-------------------------------------------------------
set Rs=server.CreateObject("ADODB.RecordSet")
sql="select count(sortid) from (Select ROW_NUMBER() OVER (order by endtime asc,id desc ) as sortid,* From AuctionsOrder) as TempTable where 1=1 "&sqlsearch&""
Pager_Pagesize=10 '每页记录数
Rs.open sql,conn,1,1
Pager_TotalRecord=Rs(0) '总记录数
Rs.close
Pager_PageCount=int((Pager_TotalRecord/Pager_Pagesize)+0.99999) '计算总页数
CurrentPage=Request("page") '当前页
'如果不为数字则直接设置页码为1
if isnumeric(CurrentPage)=False Or CurrentPage="" then
	CurrentPage=1
'如果当前页数大于总页数，则直接设置页码为1
elseif  Clng(CurrentPage)>Pager_PageCount then
	CurrentPage=1
end if
Fieldsname=" id,uid,pic,url,title,Itemnumber,SellerID,bidmark,Endtime,price,BidsPrice,bail,type,addtime,sortid"
orderBy=" Order by sortid asc"
'拆分SQL语句，必须是select开头，有唯一标识的列
if instr("select",sql)<>-1 then
	if CurrentPage = 1 then
		sql = replace(sql,"select count(sortid)"," select  top " & Pager_Pagesize  & Fieldsname)
	else  
		sql = replace(sql,"select count(sortid)"," select  top " & Pager_Pagesize   & Fieldsname) & " and sortid >(select max(sortid) from (" & replace(sql,"select count(sortid)"," select  top " & Pager_Pagesize * (CurrentPage - 1)  & Fieldsname) & orderBy & ") AA)"
	end if
end if
sql = sql & orderBy
Rs.open sql,conn,1,1
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>main</title>
<link href="../css/style.css" rel="stylesheet" type="text/css"/>
</head>

<body>
<div class="main">
  <div class="main-title">查看 <a target="_blank" href="work.asp">系统工作</a></div>
  <div class="main-content">
  <table width="100%" border="0" cellspacing="1" cellpadding="3" class="tab">
  <tr>
    <td colspan="6" align="center">
    <form name="form" method="get" action="">
    商品名<input name="key" type="text" id="key" value="<%=key%>" maxlength="50" />
     标号<input name="Itemnumber" type="text" id="Itemnumber" value="<%=Itemnumber%>" maxlength="50" />
      卖家ID<input name="SellerID" type="text" id="SellerID" value="<%=SellerID%>" maxlength="50" />
      UID<input name="uid" type="text" id="uid" value="<%=uid%>" maxlength="50" />
    <input name="typeid" type="hidden" value="<%=request("typeid")%>" />
    <input type="submit" name="search" value="搜索" />
    </form>
    </td>
    </tr>
    </table>
  <table width="100%" border="0" cellspacing="1" cellpadding="3" class="tab">
  <form action="" method="post">
  <tr>
    <td align="center" bgcolor="#FFFFFF"><strong>选择</strong></td>
    <td align="center" bgcolor="#FFFFFF"><strong>卖家ID</strong></td>
    <td align="center" bgcolor="#FFFFFF"><strong>标号</strong></td>
    <td colspan="2" align="center" bgcolor="#FFFFFF"><strong><span class="items">商品</span></strong></td>
    <td align="center" bgcolor="#FFFFFF"><strong><span class="items">剩余时间</span></strong></td>
    <td align="center" bgcolor="#FFFFFF"><strong>价格</strong></td>
    <td align="center" bgcolor="#FFFFFF"><strong>雅虎出价状态</strong></td>
    <td align="center" bgcolor="#FFFFFF"><strong>保证金</strong></td>
    <td align="center" bgcolor="#FFFFFF"><strong>类型</strong></td>
    <td align="center" bgcolor="#FFFFFF"><strong>会员</strong></td>
    <td bgcolor="#FFFFFF">会员ID</td>
    <td bgcolor="#FFFFFF"><strong>添加时间</strong></td>
    </tr>
    <%do while not Rs.eof%>
  <tr>
    <td align="center" bgcolor="#FFFFFF"><input type="checkbox" name="checkbox" id="checkbox" value="<%=rs("id")%>" <%if typeid<>"5" then response.Write " disabled "%>/></td>
    <td align="center" bgcolor="#FFFFFF"><a target="_blank" href="http://store.auctions.yahoo.co.jp/html/profile/<%=rs("SellerID")%>.html"><%=rs("SellerID")%></a> <a target="_blank" href="http://rating.auctions.yahoo.co.jp/jp/show/rating?userID=<%=rs("SellerID")%>">评价</a></td>
    <td align="center" bgcolor="#FFFFFF"><%=rs("Itemnumber")%></td>
    <td bgcolor="#FFFFFF"><a title="进入本站查看" target="_blank" href="/auctions/<%=rs("Itemnumber")%>.html?s=t"><img src="<%=rs("pic")%>" height="50" /></a></td>
    <td bgcolor="#FFFFFF"><a title="进入雅虎查看" target="_blank" href="<%=rs("url")%>"><%=left(rs("title"),15)%></a></td>
    <td align="center" bgcolor="#FFFFFF"><%if rs("endtime")<now() then%>
      <strong>已结束</strong>
      <%else%>
      <span class="strong" id="spanMkshy<%=rs("id")%>" ></span><SCRIPT language=javascript>
<!--
function showMkshy<%=rs("id")%>(){
window.setTimeout("showMkshy<%=rs("id")%>()", 1000);
BirthDay=new Date("<%=replace(rs("endtime"),"-","/")%>");//改成你的计时日期
today=new Date();
timeold=(BirthDay.getTime()-today.getTime());
sectimeold=timeold/1000
secondsold=Math.floor(sectimeold);
msPerDay=24*60*60*1000
e_daysold=timeold/msPerDay
daysold=Math.floor(e_daysold);
e_hrsold=(e_daysold-daysold)*24;
hrsold=Math.floor(e_hrsold);
e_minsold=(e_hrsold-hrsold)*60;
minsold=Math.floor((e_hrsold-hrsold)*60);
seconds=Math.floor((e_minsold-minsold)*60);
//spanMkshy.innerHTML=daysold+"天"+hrsold+"时"+minsold+"分"+seconds+"秒" ;
document.getElementById("spanMkshy<%=rs("id")%>").innerHTML=daysold+"天"+hrsold+"时"+minsold+"分"+seconds+"秒" ;
}
showMkshy<%=rs("id")%>();
//-->
</SCRIPT>
   <%end if%> </td>
    <td align="center" bgcolor="#FFFFFF">
	<%=rs("BidsPrice")%>日元 | <%=cdbl(rs("BidsPrice"))*web_rate%> RMB 出价 <br />
    <%=rs("price")%>日元 | <%=cdbl(rs("price"))*web_rate%> RMB 当前
    </td>
    <td align="center" bgcolor="#FFFFFF"><%
		  select case rs("bidmark")
		  case 0: response.write("<font color='red'>出价失败</font>")
		  case 1: response.write("未出价")
		  case 2: response.write("已出价")
	      end select
		  %></td>
    <td align="center" bgcolor="#FFFFFF"><%=rs("bail")%>RMB</td>
    <td align="center" bgcolor="#FFFFFF"><%if rs("type")="0" then response.Write "出价竞拍" else response.Write "预约出价"%></td>
    <td align="center" bgcolor="#FFFFFF"><%set rss=conn.execute("select mail,id from [user] where uid='"&rs("uid")&"'")
		                               if not rss.eof then
		                               response.write rss("mail")
									   end if
									   set rss=nothing%></td>
    <td align="center" bgcolor="#FFFFFF"><%=rs("uid")%></td>
    <td bgcolor="#FFFFFF"><%=rs("addtime")%></td>
    </tr>
    <%
	Rs.movenext
	loop
	Rs.close
	Set Rs=nothing
	%>
    <tr>
      <td colspan="13" align="center" bgcolor="#FFFFFF" class="page">
      <%if typeid="5" then%>
<input type="submit" name="button" id="button" value="中标" />
      <input type="submit" name="button" id="button" value="落标">  
      <%end if%>
      </td>
    </tr>
    </form>
    <tr>
    <td colspan="13" align="center" bgcolor="#FFFFFF" class="page">　
      <%
	siteurl=request.servervariables("document_name")
	%>
    <form action="<%=siteurl%>" method="get">
    共 <%=Pager_TotalRecord%> 条 第<%=CurrentPage%>页 / 共 <%=Pager_PageCount%> 页
		<%
		pageurl="key="&key&"&Itemnumber="&Itemnumber&"&SellerID="&SellerID&"&uid="&uid&"&typeid="&typeid&"&mark="&mark&"&search="&search&"&"
		if CurrentPage=1 then
			response.Write(" 首页 ")
			response.Write(" 上一页 ")
		else
			response.Write(" <a href='"&siteurl&"?"&pageurl&"page=1'>首页</a> ")
			response.Write(" <a href='"&siteurl&"?"&pageurl&"page="& (CurrentPage-1) &"'>上一页</a> ")
		end if
		%>
		<%
		if Clng(CurrentPage)=Clng(Pager_PageCount) then
			response.Write(" 下一页 ")
			response.Write(" 尾页 ")
		else
			response.Write(" <a href='"&siteurl&"?"&pageurl&"page="& (CurrentPage+1) &"'>下一页</a> ")
			response.Write(" <a href='"&siteurl&"?"&pageurl&"page="& Pager_PageCount &"'>尾页</a> ")
		end if
		%>
		&nbsp;
		<input name="page" type="text" value="<%=CurrentPage%>" size="1" maxlength="10" />
        <input type="submit" name="button" value="跳转" />
        <input type="hidden" name="key" value="<%=key%>" />
        <input type="hidden" name="mark" value="<%=mark%>" />
        <input type="hidden" name="Itemnumber" value="<%=Itemnumber%>" />
        <input type="hidden" name="SellerID" value="<%=SellerID%>" />
        <input type="hidden" name="uid" value="<%=uid%>" />
        <input type="hidden" name="typeid" value="<%=typeid%>" />
        <input type="hidden" name="search" value="搜索" />
        </form>
        
        
      </td>
    </tr>
  </table>
</div>
</div>
<script type="text/javascript">setTimeout('window.location.replace(location.href)', 50000);</script>
</body>
</html>
<%
checkbox=request.Form("checkbox")
if checkbox<>"" then	
	if request.Form("button")="中标" then
		conn.execute("update AuctionsOrder set type=2 where id in ("&checkbox&")")

	elseif request.Form("button")="落标" then
		moneyuser=split(replace(checkbox," ",""),",")
        for f=0 to ubound(moneyuser)
		   set rss=conn.execute("select * from AuctionsOrder where id="&moneyuser(f)&"")
		   if not rss.eof then
	         '增加会员产品交易失败金额
			      conn.execute("update [user] set money=money+"&rss("bail")&" where uid = '"&rss("uid")&"'")
			    
				set rsuser=conn.execute("select money from [user] where uid='"&rss("uid")&"'")
				  '增加产品交易失败金额明细
				  set rsx=server.createobject("adodb.recordset")
				  sql="select * from funds" 
				  rsx.open sql,conn,1,3
				  rsx.addnew  
				  rsx("Uid")=rss("uid")
				  rsx("money")=rss("bail")
				  rsx("Balance")=cdbl(rsuser("money"))-cdbl(rss("bail"))
				  rsx("content")=request.cookies("admin")("name")&"操作,竞拍商品交易失败"&rss("title")&rss("Itemnumber")
				  rsx("Type")=3
				  rsx("PayType")=2
				  rsx("mark")=1
				  rsx.update
				  rsx.close
				  set rsx=nothing   
                set rsuser=nothing
	  
		   set rss=nothing
		   end if  
		next
		conn.execute("update AuctionsOrder set type=3 where id in ("&checkbox&")")
	end if
	response.Redirect "order.asp?typeid="&typeid&"&page="&request.QueryString("page")&""
end if
%>